package com.business.form.action;

import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.dubbo.common.URL;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.business.base.BaseController;
import com.business.base.Pager;
import com.business.form.po.FormBean;
import com.business.form.po.FormReadBean;
import com.business.form.service.FormButtonService;
import com.business.form.service.FormColumnService;
import com.business.form.service.FormControlService;
import com.business.form.service.FormFilterService;
import com.business.form.service.FormParamsService;
import com.business.form.service.FormParamsValueService;
import com.business.form.service.FormPublish;
import com.business.form.service.FormReadService;
import com.business.form.service.FormSaveService;
import com.business.form.service.FormService;
import com.business.form.service.FormTabService;
import com.business.frame.service.FieldService;
import com.common.BeanUtil;
import com.common.ContextUtils;
import com.common.DateProcess;
import com.common.DecimalProcess;
import com.common.ErrorLog;
import com.common.FileUtil;
import com.common.NumberProcess;
import com.common.RenderPage;
import com.common.StringProcess;
import com.common.utils.SpringContextHolder;


/**
 * @author jpx 
 * @version 1.0
 * @since 1.0
 */

@Controller
@RequestMapping(value="/form/form")
public class FormController{
	
	@Autowired
	FormService formService;
	
	@Autowired
	FormTabService formTabService;
	
	@Autowired
	FormButtonService formButtonService;
	
	@Autowired
	FormSaveService formSaveService;
	
	@Autowired
	FormReadService formReadService;
	
	@Autowired
	FormParamsService formParamsService;
	
	@Autowired
	FormParamsValueService formParamsValueService;

	@Autowired
	FormFilterService formFilterService;
	
	@Autowired
	FormControlService formControlService;
	
	@Autowired
	FormColumnService formColumnService;
	
	@Autowired
	FieldService fieldService;
	
	@RequestMapping(value="/list")
	public String list(HttpServletRequest request,ModelMap model) {
		return "/form/form/list";
	}

	@RequestMapping({ "/detail" })
	public String detail(HttpServletRequest request, ModelMap model) {
		try{

		    String formId = StringProcess.getRequest(request.getParameter("formId"), "");

		    
		    //test
		    //FileUtil.writeFile();
		    
		    
			//初始化控件
						
			String action = "";
			String pageClassifyCode="";
			FormBean bean=new FormBean();
			FormReadBean readBean=new FormReadBean();
			if (formId.length() == 0) {
				action = "insert";
			    formId = StringProcess.getUUID();
				bean.setFormId(formId);
				
				//readBean.setId("");
				
			} else {
				action = "update";
				bean=formService.getBeanByKeyId(formId);
				pageClassifyCode=bean.getPageClassifyCode();
				
				readBean=formReadService.getBeanByFormId(formId);
			}
			
			Map<String, Object> paramMap;
			List<Map<String,Object>> list;
			Map<String, Object> item;
			String rowData;
			
			if(pageClassifyCode.equals("bdy"))
			{
				//加载Tab页
				paramMap = new HashMap<String, Object>();
				paramMap.put("formId",formId);
				List<Map<String, Object>> listFormTab = formTabService.select(paramMap);
				list = new ArrayList<Map<String, Object>>();
				for(int i=0;i<listFormTab.size();i++)
				{
					Map<String, Object> itemFormTab=listFormTab.get(i);
	
					item=new HashMap<String, Object>();
					item.put("hidFormTabId", itemFormTab.get("FormTabId").toString());
					item.put("txtFormTabTitle", itemFormTab.get("FormTabTitle").toString());
					if(itemFormTab.get("IsShow").toString().equals("1"))
					{
						item.put("rdoIsShow1", "1");
					}
					else
					{
						item.put("rdoIsShow2", "0");
					}
					item.put("txtOrderNumber", itemFormTab.get("OrderNumber").toString());
					
					list.add(item);
				}
				rowData=JSON.toJSONString(list);
				rowData = StringProcess.encode(rowData);
				model.put("rowData1", rowData);
			}
			
			if(pageClassifyCode.equals("bdy") || pageClassifyCode.equals("lby") || pageClassifyCode.equals("tjy"))
			{
				//加载Button
				paramMap = new HashMap<String, Object>();
				paramMap.put("formId",formId);
				List<Map<String, Object>> listFormButton = formButtonService.select(paramMap);
				list = new ArrayList<Map<String, Object>>();
				for(int i=0;i<listFormButton.size();i++)
				{
					Map<String, Object> itemFormButton=listFormButton.get(i);
					
					item=new HashMap<String, Object>();
					item.put("hidButtonId", itemFormButton.get("ButtonId").toString());
					item.put("txtButtonTitle", itemFormButton.get("ButtonTitle").toString());
					item.put("txtButtonAction", itemFormButton.get("ButtonAction").toString());
					item.put("txtButtonScript", StringProcess.decode(itemFormButton.get("ButtonScript").toString()));
					item.put("txtOrderNumber", itemFormButton.get("OrderNumber").toString());
					
					list.add(item);
				}
				rowData=JSON.toJSONString(list);
				rowData = StringProcess.encode(rowData);
				model.put("rowData2", rowData);
			}
			
			
			if(pageClassifyCode.equals("bdy"))
			{
				//加载FormSave
				paramMap = new HashMap<String, Object>();
				paramMap.put("formId",formId);
				paramMap.put("saveType",1);
				List<Map<String, Object>> listFormSave = formSaveService.select(paramMap);
				String saveTableId="";
				String saveTableName="";
				for(int i=0;i<listFormSave.size();i++)
				{
					if(i>0)
					{
						saveTableId+=",";
						saveTableName+=",";
					}
					saveTableId+=listFormSave.get(i).get("SaveTableId");
					saveTableName+=listFormSave.get(i).get("SaveTableName");
				}
				model.put("saveTableId", saveTableId);
				model.put("saveTableName", saveTableName);
			}
			
			
			if(pageClassifyCode.length()>0)
			{
				//参数列
				paramMap = new HashMap<String, Object>();
				int objectType=convertByPageClassifyCode(pageClassifyCode);
				paramMap.put("objectType",objectType);
				paramMap.put("objectId",formId);
				List<Map<String, Object>> listFormParams = formParamsService.select(paramMap);
				
				BaseController.ProcessParams(model, listFormParams);
			}
			
			
			if(pageClassifyCode.equals("lby") || pageClassifyCode.equals("tjy"))
			{
				//加载FormRead
				paramMap = new HashMap<String, Object>();
				paramMap.put("formId",formId);
				paramMap.put("readType",1);
				List<Map<String, Object>> listFormRead = formReadService.select(paramMap);
				if(listFormRead.size()>0)
				{
					Map<String, Object> itemFormRead=listFormRead.get(0);
					model.put("itemFormRead", itemFormRead);
				}
			}

			
			if(pageClassifyCode.equals("lby") || pageClassifyCode.equals("tjy"))
			{
				//加载FormFilter
				paramMap = new HashMap<String, Object>();
				paramMap.put("formId",formId);
				List<Map<String, Object>> listFormFilter = formFilterService.select(paramMap);
				list = new ArrayList<Map<String, Object>>();
				for(int i=0;i<listFormFilter.size();i++)
				{
					Map<String, Object> itemFormFilter=listFormFilter.get(i);
					
					item=new HashMap<String, Object>();
					item.put("hidFormFilterId", itemFormFilter.get("FormFilterId").toString());
					item.put("txtFormFilterTitle", itemFormFilter.get("FormFilterTitle").toString());
					item.put("hidFilterTableId", itemFormFilter.get("FilterTableId").toString());
					item.put("hidFilterTableName", itemFormFilter.get("FilterTableName").toString());
					item.put("hidFilterFieldId", itemFormFilter.get("FilterFieldId").toString());
					item.put("txtFilterFieldName", itemFormFilter.get("FilterFieldName").toString());
					item.put("lstFormControlType", itemFormFilter.get("FormControlType").toString());
					item.put("lstExpression", itemFormFilter.get("Expression").toString());
					item.put("txtOrderNumber", itemFormFilter.get("OrderNumber").toString());
					
					list.add(item);
				}
				rowData=JSON.toJSONString(list);
				rowData = StringProcess.encode(rowData);
				model.put("rowData3", rowData);
			}
			
			
			model.put("action", action);
			model.put("bean", bean);
			model.put("readBean", readBean);
			model.put("root", ContextUtils.getContextPath(request));
			
		}catch(Exception e){
			ErrorLog.OnWrite(e);
		}
		
		return "form/form/detail";
	}
	
	private int convertByPageClassifyCode(String pageClassifyCode)
	{
		int ret=0;
		
		if(pageClassifyCode.equals("bdy"))
		{
			ret=1;
		}
		else if(pageClassifyCode.equals("lby"))
		{
			ret=2;
		}
		else if(pageClassifyCode.equals("tjy"))
		{
			ret=3;
		}
		else if(pageClassifyCode.equals("dhy"))
		{
			ret=4;
		}
		
		return ret;
	}
	
	@RequestMapping("/query")
	public void query(Integer pageIndex, Integer pageSize, HttpServletRequest request, HttpServletResponse response,
			ModelMap map) {
			
		try{
			Map<String, Object> search = new HashMap<String, Object>();
			String formTitle = request.getParameter("txtFormTitle");
			if(StringUtils.isNotEmpty(formTitle)){
				search.put("formTitle", "%"+formTitle+"%");
			}
			//筛选条件
			
			Pager<Map<String, Object>> result = formService.selectPage(pageIndex,pageSize,search);
			
			int resultCount = result.getList().size();
			for (int i = 0; i < resultCount; i++) {
				Map<String, Object> item = result.getList().get(i);
				
				item.put("FormVersion",DecimalProcess.convertToFormat(item.get("FormVersion"),"0.0"));
				item.put("UpdateTime", DateProcess.convertToString(item.get("UpdateTime"), "yyyy-MM-dd"));
			}
			
			RenderPage.JsonByObject(response, result);
			
		}catch(Exception e){
			ErrorLog.OnWrite(e);
		}
		
	}
	
	@RequestMapping(params = "method=publish", method = RequestMethod.POST)
	public void publish(HttpServletRequest request, HttpServletResponse response) {
	
		String msg="";
		
		try
		{
			String formId = StringProcess.convertToString(request.getParameter("formId"));
			if(formId.length()>0)
			{
				//发布页面
				Map<String,Object> service=new HashMap<String, Object>();
				service.put("Form", formService);
				service.put("FormTab", formTabService);
				service.put("FormButton", formButtonService);
				service.put("FormRead", formReadService);
				service.put("FormSave", formSaveService);
				service.put("FormFilter", formFilterService);
				service.put("FormParams", formParamsService);
				
				msg=FormPublish.NewInstance().OnPublic(request,formId,service,fieldService);
			}
			else
			{
				msg="发布缺少formId的Url参数！";
			}
			
			
		} catch (Exception e) {
			ErrorLog.OnWrite(e);
		}
		
		RenderPage.JsonByString(response, msg);
		
	}
	
	@RequestMapping(params = "method=save", method = RequestMethod.POST)
	public void save(HttpServletRequest request, HttpServletResponse response) {

		try {
			String action = request.getParameter("action");
			String formId = request.getParameter("txtFormId");
			String formTitle = request.getParameter("txtFormTitle");
			String formVersion = request.getParameter("txtFormVersion");
			String saveFolderName = request.getParameter("txtSaveFolderName");
			String saveFileName = request.getParameter("txtSaveFileName");
			String pageClassifyId = request.getParameter("hidPageClassifyId");
			String pageClassifyCode = request.getParameter("hidPageClassifyCode");
			String pageClassifyName = request.getParameter("txtPageClassifyName");
			String formInitScript = request.getParameter("txtFormInitScript");
			String formShowScript = request.getParameter("txtFormShowScript");

			Map<String, Object> model = new HashMap<String, Object>();
			model.put("formId", formId);
			model.put("formTitle", formTitle);
			model.put("formVersion", formVersion);
			model.put("saveFolderName", saveFolderName);
			model.put("saveFileName", saveFileName);
			model.put("pageClassifyId", pageClassifyId);
			model.put("pageClassifyCode", pageClassifyCode);
			model.put("pageClassifyName", pageClassifyName);
			model.put("formInitScript", formInitScript);
			model.put("formShowScript", formShowScript);
			Date updateTime=new Date();
			model.put("updateTime", updateTime);
					
			
			if(pageClassifyCode.equals("bdy"))
			{
				//表单页签
				String dyRowValue1 = request.getParameter("hidDyRow1");
				List<Map<String,Object>> listFormTab=new ArrayList<Map<String, Object>>();
				if(dyRowValue1!=null && dyRowValue1.length()>0)
				{
					dyRowValue1 = StringProcess.decode(dyRowValue1);
					listFormTab = JSON.parseObject(dyRowValue1, new TypeReference<List<Map<String,Object>>>(){});
				}
				
				saveFormTab(listFormTab,formId);
			}
			
			if(pageClassifyCode.equals("bdy") || pageClassifyCode.equals("lby") || pageClassifyCode.equals("tjy"))
			{
				//Button
				String dyRowValue2 = request.getParameter("hidDyRow2");
				List<Map<String,Object>> listFormButton=new ArrayList<Map<String, Object>>();
				if(dyRowValue2!=null && dyRowValue2.length()>0)
				{
					dyRowValue2 = StringProcess.decode(dyRowValue2);
					listFormButton = JSON.parseObject(dyRowValue2, new TypeReference<List<Map<String,Object>>>(){});
				}
				
				saveFormButton(listFormButton,formId);
			}
			
			if(pageClassifyCode.equals("bdy"))
			{
				//FormSave
				String saveTableId = request.getParameter("hidSaveTableId");
				String saveTableName = request.getParameter("txtSaveTableName");
				
				saveFormSave(saveTableId,saveTableName,formId);
			}
			
			if(pageClassifyCode.length()>0)
			{
				//FormParams
				String formParamIds=request.getParameter("hidFormParamIds");
				List<Map<String,Object>> listFormParams=new ArrayList<Map<String, Object>>();
				if(formParamIds.length()>0)
				{
					String[] formParamIdArray=formParamIds.split(",");
					for(int i=0;i<formParamIdArray.length;i++)
					{
						Map<String,Object> itemFormParams=new HashMap<String, Object>();
						String paramsId=formParamIdArray[i];
					
						itemFormParams.put("ParamsValueId", request.getParameter("cv_"+paramsId));
						itemFormParams.put("ParamsId", paramsId);
						itemFormParams.put("ObjectId", formId);
						itemFormParams.put("ParamsValue", request.getParameter("c_"+paramsId));
						listFormParams.add(itemFormParams);
					}
					
					saveParams(listFormParams,formId,pageClassifyCode);
				}
			}
			
			if(pageClassifyCode.equals("lby") || pageClassifyCode.equals("tjy"))
			{
				//FormRead
				String id=request.getParameter("hidId");
				int readType=1;
				String readTableId=request.getParameter("hidReadTableId");
				String readTableName=request.getParameter("txtReadTableName");
				String keyFieldName=request.getParameter("txtKeyFieldName");
				String sqlshowField=request.getParameter("txtSQLShowField");
				String sqlfromTable=request.getParameter("txtSQLFromTable");
				String sqlwhereField=request.getParameter("txtSQLWhereField");
				String sqlorderField=request.getParameter("txtSQLOrderField");
				String sqlgroupField=request.getParameter("txtSQLGroupField");
				
				Map<String, Object> readModel = new HashMap<String, Object>();
				readModel.put("id", id);
				readModel.put("readType", readType);
				readModel.put("formId", formId);
				readModel.put("readTableId", readTableId);
				readModel.put("readTableName", readTableName);
				readModel.put("keyFieldName", keyFieldName);
				readModel.put("sqlshowField", sqlshowField);
				readModel.put("sqlfromTable", sqlfromTable);
				readModel.put("sqlwhereField", sqlwhereField);
				readModel.put("sqlorderField", sqlorderField);
				readModel.put("sqlgroupField", sqlgroupField);
				
				saveFormRead(readModel);
			}
			
			if(pageClassifyCode.equals("lby") || pageClassifyCode.equals("tjy"))
			{
				//FormFilter
				String dyRowValue3 = request.getParameter("hidDyRow3");
				List<Map<String,Object>> listFormFilter=new ArrayList<Map<String, Object>>();
				if(dyRowValue3!=null && dyRowValue3.length()>0)
				{
					dyRowValue3 = StringProcess.decode(dyRowValue3);
					listFormFilter = JSON.parseObject(dyRowValue3, new TypeReference<List<Map<String,Object>>>(){});
				}
				
				saveFormFilter(listFormFilter,formId);
			}
			
			Map<String,Object> formDataMap;
			//收集数据
			FormBean formBean;
			if(action.equals("insert"))
			{
				formBean=BeanUtil.convertBeanByMap(model, FormBean.class);
			}
			else
			{
				formBean=formService.getBeanByKeyId(formId);
			}
			
			String formData=formBean.getFormData();
			if(formData==null || formData.length()==0)
			{
				formDataMap=new HashMap<String, Object>();
			}
			else
			{
				formDataMap=JSON.parseObject(formData, new TypeReference<Map<String,Object>>(){});
			}
			formBean.setFormData("");
			formDataMap.put("Form", formBean);
			if(pageClassifyCode.equals("bdy"))
			{
				formDataMap.put("FormTab", formTabService.selectByFormId(formId));
				formDataMap.put("FormSave", formSaveService.selectByFormId(formId));
			}
			else if(pageClassifyCode.equals("lby") || pageClassifyCode.equals("tjy"))
			{
				formDataMap.put("FormRead", formReadService.selectByFormId(formId));
				formDataMap.put("FormFilter", formFilterService.selectByFormId(formId));
			}
			formDataMap.put("FormButton", formButtonService.selectByFormId(formId));
			formDataMap.put("FormParams", formParamsService.selectByFormId(formId));

			//收集数据
			formData=JSON.toJSONString(formDataMap);
			model.put("formData", formData);
			model.put("isSync", 0);
			
			if (action.equals("insert")) {
				
				Date createTime=new Date();
				model.put("createTime", createTime);
				
				formService.insert(model);

			} else if (action.equals("update")) {
				formService.update(model);
			}

			RenderPage.JsonByString(response, "1");
			
		} catch (Exception e) {
			ErrorLog.OnWrite(e);
		}
	}
	
	private void saveFormTab(List<Map<String,Object>> listFormTab,String formId)
	{
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("formId",formId);
		List<Map<String, Object>> list = formTabService.select(paramMap);
		
		List<Map<String, Object>> listFormTab2=new ArrayList<Map<String, Object>>();
		for(int i=0;i<listFormTab.size();i++)
		{
			Map<String, Object> itemFormTab=listFormTab.get(i);
			String formTabId=itemFormTab.get("hidFormTabId").toString();
			String formTabTitle=itemFormTab.get("txtFormTabTitle").toString();
			Object show1=itemFormTab.get("rdoIsShow1");
			Object show2=itemFormTab.get("rdoIsShow2");
			String isShow="1";
			if(show1==null && show2!=null)
			{
				isShow="0";
			}
			String orderNumber=itemFormTab.get("txtOrderNumber").toString();
			
			Map<String, Object> itemFormTab2=new HashMap<String, Object>();
			itemFormTab2.put("FormTabId", formTabId);
			itemFormTab2.put("FormId", formId);
			itemFormTab2.put("FormTabTitle", formTabTitle);
			itemFormTab2.put("IsShow", NumberProcess.convertToNumber(isShow));
			itemFormTab2.put("OrderNumber", NumberProcess.convertToNumber(orderNumber));
			listFormTab2.add(itemFormTab2);
			
		}
		
		BaseController.OnSaveList(SpringContextHolder.getBean(FormTabService.class), listFormTab2, list, "FormTabId","FormId","FormTabTitle,IsShow,OrderNumber",true);
		
	}
	
	private void saveFormButton(List<Map<String,Object>> listFormButton,String formId)
	{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("formId",formId);
		List<Map<String, Object>> list = formButtonService.select(paramMap);
		
		List<Map<String, Object>> listFormButton2=new ArrayList<Map<String, Object>>();
		for(int i=0;i<listFormButton.size();i++)
		{
			Map<String, Object> itemFormButton=listFormButton.get(i);
			String buttonId=itemFormButton.get("hidButtonId").toString();
			String buttonTitle=itemFormButton.get("txtButtonTitle").toString();
			String buttonAction=itemFormButton.get("txtButtonAction").toString();
			String buttonScript=itemFormButton.get("txtButtonScript").toString();
			String orderNumber=itemFormButton.get("txtOrderNumber").toString();
			
			Map<String, Object> itemFormButton2=new HashMap<String, Object>();
			itemFormButton2.put("ButtonId", buttonId);
			itemFormButton2.put("FormId", formId);
			itemFormButton2.put("ButtonTitle", buttonTitle);
			itemFormButton2.put("ButtonAction", buttonAction);
			itemFormButton2.put("ButtonScript", StringProcess.encode(buttonScript));
			itemFormButton2.put("OrderNumber", NumberProcess.convertToNumber(orderNumber));
			listFormButton2.add(itemFormButton2);
			
		}
		
		BaseController.OnSaveList(SpringContextHolder.getBean(FormButtonService.class), listFormButton2, list, "ButtonId","FormId","ButtonTitle,ButtonAction,ButtonScript,OrderNumber",true);
		
	}
	
	private void saveFormSave(String saveTableId,String saveTableName,String formId)
	{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("saveType",1);
		paramMap.put("formId",formId);
		List<Map<String, Object>> list = formSaveService.select(paramMap);
		
		List<Map<String, Object>> listFormSave2=new ArrayList<Map<String, Object>>();
		String[] saveTableIdArray=saveTableId.split(",");
		String[] saveTableNameArray=saveTableName.split(",");
		for(int i=0;i<saveTableIdArray.length;i++)
		{
			Map<String, Object> itemFormSave2=new HashMap<String, Object>();
			String id="";
			for(int j=0;j<list.size();j++)
			{
				if(list.get(j).get("SaveTableId").equals(saveTableIdArray[i]))
				{
					id=list.get(j).get("Id").toString();
				}
			}
			itemFormSave2.put("Id", id);
			itemFormSave2.put("SaveType", 1);
			itemFormSave2.put("FormId", formId);
			itemFormSave2.put("FormControlId", "");
			itemFormSave2.put("SaveTableId", saveTableIdArray[i]);
			itemFormSave2.put("SaveTableName", saveTableNameArray[i]);
			itemFormSave2.put("SaveFieldId", "");
			itemFormSave2.put("SaveFieldName", "");
			listFormSave2.add(itemFormSave2);
		}
		
		BaseController.OnSaveList(SpringContextHolder.getBean(FormSaveService.class), listFormSave2, list, "Id","FormId","SaveType,FormControlId,SaveTableId,SaveTableName,SaveFieldId,SaveFieldName",false);
	}
	
	private void saveParams(List<Map<String,Object>> listFormParams,String formId,String pageClassifyCode)
	{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		int objectType=convertByPageClassifyCode(pageClassifyCode);
		paramMap.put("objectType",objectType);
		paramMap.put("objectId",formId);
		List<Map<String, Object>> list = formParamsService.select(paramMap);
		
		BaseController.OnSaveList(SpringContextHolder.getBean(FormParamsValueService.class), listFormParams, list, "ParamsValueId","ObjectId","ParamsId,ParamsValue",true);
	}
	
	private void saveFormRead(Map<String,Object> readModel)
	{
		if(readModel.get("id").toString().length()>0)
		{
			formReadService.update(readModel);
		}
		else
		{
			readModel.put("id", StringProcess.getUUID());
			formReadService.insert(readModel);
		}
	}
	
	private void saveFormFilter(List<Map<String,Object>> listFormFilter,String formId)
	{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("formId",formId);
		List<Map<String, Object>> list = formFilterService.select(paramMap);
		
		List<Map<String, Object>> listFormFilter2=new ArrayList<Map<String, Object>>();
		for(int i=0;i<listFormFilter.size();i++)
		{
			Map<String, Object> itemFormButton=listFormFilter.get(i);
			String formFilterId=itemFormButton.get("hidFormFilterId").toString();
			String formFilterTitle=itemFormButton.get("txtFormFilterTitle").toString();
			String filterTableId=itemFormButton.get("hidFilterTableId").toString();
			String filterTableName=StringProcess.convertToString(itemFormButton.get("hidFilterTableName"));
			String filterFieldId=itemFormButton.get("hidFilterFieldId").toString();
			String filterFieldName=itemFormButton.get("txtFilterFieldName").toString();
			String formControlType=itemFormButton.get("lstFormControlType").toString();
			String expression=itemFormButton.get("lstExpression").toString();
			String orderNumber=itemFormButton.get("txtOrderNumber").toString();
			
			Map<String, Object> itemFormFilter2=new HashMap<String, Object>();
			itemFormFilter2.put("FormFilterId", formFilterId);
			itemFormFilter2.put("FormId", formId);
			itemFormFilter2.put("FormFilterTitle", formFilterTitle);
			itemFormFilter2.put("FilterTableId", filterTableId);
			itemFormFilter2.put("FilterTableName", filterTableName);
			itemFormFilter2.put("FilterFieldId", filterFieldId);
			itemFormFilter2.put("FilterFieldName", filterFieldName);
			itemFormFilter2.put("FormControlType", NumberProcess.convertToNumber(formControlType));
			itemFormFilter2.put("Expression", NumberProcess.convertToNumber(expression));
			itemFormFilter2.put("OrderNumber", NumberProcess.convertToNumber(orderNumber));
			listFormFilter2.add(itemFormFilter2);
			
		}
		
		BaseController.OnSaveList(SpringContextHolder.getBean(FormFilterService.class), listFormFilter2, list, "FormFilterId","FormId","FormFilterTitle,FilterTableId,FilterTableName,FilterFieldId,FilterFieldName,FormControlType,Expression,OrderNumber",true);
		
	}
	
	@RequestMapping(params = "method=delete", method = RequestMethod.POST)
	public void del(HttpServletRequest request, HttpServletResponse response) {
		try{
			String[] array = StringProcess.getRequest(request.getParameter("selectitem"), "").split(",");
			for (String formId : array) {
				if(formId.length()>0){
					formService.delete(formId);
				}
			}
	
			RenderPage.JsonByString(response, "1");
		}catch(Exception e){
			ErrorLog.OnWrite(e);
		}
		
	}
}
